<?php

class Persona extends CI_Controller{
private $data;
	public function __construct(){
		parent::__construct();
		$this->data['url1']=site_url(array("persona","persona","guardar"));
		$this->data['url2']=site_url(array("persona","persona","perfiles"));
		$this->data['id_menu']=1;
		session_start();
		if(!isset($_SESSION['VALID']) || $_SESSION['VALID'] != 1){
			redirect('login/login');
		}else{
			$this->data['menu']=$_SESSION['ACCESOS'];
		}
	}
	
	public function index(){		
		$this->load->view("cabecera");
		$this->load->view("menu",$this->data);
		$this->load->model("persona/persona_model");
		$this->data['per']=$this->persona_model->selectpersona();
		$this->load->view("persona/insert",$this->data);
	}
	
	public function guardar(){		
		$cedula=$this->input->post("cedula");
		$contrasena=$this->input->post("contrasena");
		$nombres=$this->input->post("nombres");
		$apellidos=$this->input->post("apellidos");
		$direccion=$this->input->post("direccion");
		$telefono=$this->input->post("telefono");
		$perfiles=$this->input->post("perfiles");
		$this->load->model("persona/persona_model");
		$this->persona_model->insert($cedula,$nombres,$apellidos,$direccion,$telefono);
		if(isset($perfiles) && $perfiles!="")  
	   {
		  $cedula=(int) $cedula;
		  echo $this->persona_model->insertUsuario($cedula,$perfiles,$contrasena);
	   }else{
			echo $this->persona_model->insertTestigo($cedula);
	   }
	}
	public function perfiles(){
		$perfil=$this->input->post("tipo");
		$this->load->model("persona/persona_model");
		$this->data['ret']=$this->persona_model->perfiles();
		$this->load->view("persona/tipo",$this->data);
	}
	
}